package www.wxwnb.clerk.ui.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import www.wxwnb.clerk.R;
import www.wxwnb.clerk.adapter.MyViewPagerAdapter;
import www.wxwnb.clerk.base.BaseActivity;
import www.wxwnb.clerk.ui.fragment.AlreadyCheckedFragment;
import www.wxwnb.clerk.ui.fragment.NotPassCheckFragment;
import www.wxwnb.clerk.ui.fragment.UnCheckedFragment;

/**
 * Created by lenovo on 2017/9/9.
 * 开户查询
 */
public class AccountOpenActivity extends BaseActivity  {

    private TabLayout mTabLayout;
    private ImageView im_back_include;
    private EditText ed_search_ac;
    private Button but_search_ac;
    private TabLayout tab_account;
    private ViewPager viewPager_account;
    private MyViewPagerAdapter adapter;
    private List<Fragment> list_f;
    private List<String> list_t;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.account_open);
        initView();
        initData();
        initListener();
    }

    @Override
    protected void initView() {
        mTabLayout = (TabLayout) findViewById(R.id.tab_account);
        im_back_include = (ImageView) findViewById(R.id.im_back_include);
        ed_search_ac = (EditText) findViewById(R.id.ed_search_ac);
        but_search_ac = (Button) findViewById(R.id.but_search_ac);
        viewPager_account = (ViewPager) findViewById(R.id.viewPager_account);
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        mTabLayout.setSelectedTabIndicatorColor(Color.parseColor("#0086ff"));

    }

    @Override
    public void initListener() {
        im_back_include.setOnClickListener(this);
        ed_search_ac.setOnClickListener(this);
        but_search_ac.setOnClickListener(this);
        viewPager_account.setOnClickListener(this);
    }

    @Override
    public void initData() {
        list_f=new ArrayList<>();
        AlreadyCheckedFragment alreadyCheckedFragment=new AlreadyCheckedFragment();
        NotPassCheckFragment notPassCheckFragment=new NotPassCheckFragment();
        UnCheckedFragment unCheckedFragment=new UnCheckedFragment();
        list_f.add(alreadyCheckedFragment);
        list_f.add(notPassCheckFragment);
        list_f.add(unCheckedFragment);
        list_t=new ArrayList<>();
        list_t.add("已审核");
        list_t.add("未审核");
        list_t.add("未通过");
        setAdapterDatas(list_f,list_t);

    }

    @Override
    public void processClick(View v) {
        switch (v.getId()) {
            case R.id.but_search_ac:
                submit();
                break;
            case R.id.im_back_include:
                finish();
                break;
        }
    }


    private void submit() {
        // validate￥
        String ac = ed_search_ac.getText().toString().trim();
        if (TextUtils.isEmpty(ac)) {
            Toast.makeText(this, "搜索不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        // TODO validate success, do something
    }

    private void setAdapterDatas(List<Fragment> list, List<String> list_t){
        if(adapter==null){
            adapter = new MyViewPagerAdapter(getSupportFragmentManager(),list,list_t);
            viewPager_account.setAdapter(adapter);
            mTabLayout.setupWithViewPager(viewPager_account);
        }else {
            adapter.notifyDataSetChanged();
        }

    }
}
